﻿@{
   
}
@section head{
}
<div class="rightbar">
    <p class="righttit">
        <span>管理中心</span></p>
    <div class="rightshow">
        <div class="listshow">
            <form method="get" id="searchForm" action="@Url.Action("AdInfoList", "AdMgr")">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="8%">
                        广告位：
                    </td>
                    <td width="20%">
                        <select name="AdAreaId" class="select">
                            <option value="">全部</option>
                            @foreach (var item in ViewBag.AdArea_Dt.Rows)
                            {
                                <option value="@item["Id"]" @(@item["Id"].ToString() == Request["AdAreaId"] ? "selected" : "")>@item["Title"]</option>                    
                            }
                        </select>
                    </td>
                    <td width="8%">
                        关键词：
                    </td>
                    <td width="20%">
                        <input type="text" name="SearchKey" id="searchKey" class="input2 text" value="@Request["SearchKey"]"  style="width:130px"/>
                    </td>
                    <td align="left">
                        <a href="###" onclick="javascript:searchForm.submit();" class="sbtn"><span class="white">
                            搜索</span></a>
                    </td>
                </tr>
            </table>
            </form>
        </div>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabtit">
            <tr>
                <td width="10%" align="center">
                    <a href="@Url.Action("AdInfoDetail")">
                        <img alt="" src="@Url.Content("~/Areas/admin/image/add.jpg")" />
                        添加广告信息</a>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tinfor1">
            <tr class="tinfor2">
                <td width="3%">
                    <input type="checkbox" name="checkbox" />
                </td>
                <td>
                    排序
                </td>
                <td>
                    广告名称
                </td>
                <td>
                    链接地址
                </td>
                <td>
                    所在位置
                </td>
                <td>
                    操作
                </td>
            </tr>
            @foreach (var single in @Model.Rows)
            {
                <tr class="tinfor3">
                    <td>
                        <input type="checkbox" name="checkbox" />
                    </td>
                    <td>
                        <input type="text" class="Sort" id="@single["Id"]" value="@single["Sort"]"  style="width:50px"/>
                    </td>
                    <td>
                        @single["AdInfoName"]
                    </td>
                    <td>
                        @single["AdLink"]
                    </td>
                    <td>
                        @single["AdAreaName"]
                    </td>
                    <td>
                        <a href="@Url.Action("AdInfoDetail", "AdMgr", new { id = @single["Id"] })" id="update">
                            修改</a>| <a href="###" id="delete" onclick='oDelete(@single["Id"])'>删除</a>
                    </td>
                </tr>
            }
        </table>
    </div>
</div>
@section Script{
    <script type="text/javascript">
        function oDelete(obj) {
            art.dialog.confirm('你确定要删除吗？', function () {
                doDelete(obj);
            }, function () {

            });
        }
        function doDelete(obj) {
            $.ajax({
                type: "POST",
                url: "/Admin/AdMgr/AdAreaDelete",
                data: { "id": obj },
                dataType: "text",
                success: function (msg) {
                    if (msg == "1") {
                        location.reload();
                    }
                    else {
                        art.dialog({
                            title: "提示",
                            icon: "warning",
                            content: "操作失败！",
                            time: 2
                        });
                    }
                },
                error: function () {
                    art.dialog({
                        title: "提示",
                        icon: "warning",
                        content: "网络忙，请稍后再试！",
                        time: 2
                    });
                }
            });
        }

        $(function () {
            $(".Sort").each(function () {
                $(this).blur(function () {
                    var id = $(this).attr("id");
                    var value = $(this).attr("value");
                    oSort(id, value);
                });
            });
        });

        //排序
        function oSort(id, value) {
            $.ajax({
                type: "POST",
                url: "/Admin/AdMgr/AdInfoSort",
                data: { "id": id, "value": value },
                dataType: "text",
                success: function (msg) {
                    if (msg == "1") {
                        art.dialog.alert("操作成功");
                    }
                    else {
                        art.dialog.alert("操作失败");
                    }
                },
                error: function () {
                    art.dialog({
                        title: "提示",
                        icon: "warning",
                        content: "网络忙，请稍后再试！",
                        time: 2
                    });
                }
            });
        }
    </script>
}
